home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / vtkerma2.arc / MSTERM.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-02-13  |  14.0 KB  |  573 lines

  1.     PAGE 59, 132
  2.  
  3.     TITLE MSTERM -- Terminal emulation module
  4.  
  5. ; Update 9 Jan 86
  6.  
  7. IF1
  8.  %OUT >> Starting pass 1
  9. ELSE
  10.  %OUT >> Starting pass 2
  11. ENDIF
  12.  
  13.     PUBLIC clscpt, defkey, cptfcb, inicpt, clscpi, telnet, Allow_blast
  14.     PUBLIC dopar, shokey, prkey, Telnet2, Quit_emulator
  15.  
  16.     INCLUDE MsDefs.H
  17.  
  18. DataS     SEGMENT    PUBLIC 'DataS'
  19.  
  20.     EXTRN flags:byte, trans:byte, DTA:BYTE, portval:word
  21.     EXTRN Preload_buffer:BYTE, Preload_flag:BYTE, TakLev:BYTE, TakAdr:WORD
  22.  
  23.     EVEN
  24.  
  25. temp    dw    0
  26. temp1   dw      ?               ; Temporary storage.
  27. temp2   dw      ?               ; Temporary storage.
  28. ssp    dw    0        ; Save SP in Telnet.
  29.  
  30. SCNTLEN    EQU 200        ; MAX # OF DEFINITIONS ONE can have
  31. defbsiz    EQU 400        ; combined length of all definitions...
  32.  
  33. scntab    dw    scntlen dup (?)    ; scan codes redefined
  34. deftab    dw    scntlen dup (?) ; pointer to definition strings
  35. defptr    dw    defbuf        ; pointer starts at beginning
  36. deflen    dw    defbsiz        ; amt of space left in buffer
  37.  
  38. targ    termarg    <0,1,80,24,cptchr,2dch,0,scntab,deftab,0,,parnon>
  39. crlf    db      cr,lf,'$'
  40. tmp    db    ?,'$'
  41.  
  42. erms22    db    '? No capture file open', Cr, Lf, '$'
  43. esctl    db    'Control-$'         ; [6]
  44.  
  45. inthlp  db    ' ?      Type this message',cr,lf
  46.     db    ' Space  Return to terminal emulation',cr,lf
  47.     db    ' B      Send a Break to the host',cr,lf
  48.     db    ' C      Close the connection (return to command mode)',cr,lf
  49.     db    ' M      Toggle Mode line (turn it on or off)',cr,lf
  50.     db    ' Q      Quit logging to file',cr,lf
  51.     db    ' R      Resume logging to file',cr,lf
  52.     db    ' S      Show Status of the connection',cr,lf
  53.     db    ' 0      Send a NUL to the host',cr,lf
  54.     db    ' Typing the escape character will send it to the host'
  55.     db    0
  56.  
  57. intprm    db    '                   Press an action key, or Space to continue$'
  58.  
  59. sttmsg    db    '                            Press any key to continue$'
  60.  
  61. CPTFCB    DB    25H DUP (?)
  62. CAPBUF    DB    200 DUP (?)
  63. CAPBP    DW    ?
  64. CAPLFT    DB    ?
  65. Allow_blast DB 0        ; Flag that rapid-fire screen updates are OK
  66.  
  67. defbuf    db    defbsiz dup (?)
  68. shkmsg    db    cr,lf,'Press key: $'
  69.  
  70. DataS    ENDS
  71.  
  72. Code    SEGMENT    PUBLIC
  73.  
  74.     extrn     comnd:near, outchr:near, stat0:near
  75.     extrn    escprt:near, clrbuf:near, term:near
  76.     extrn    cmblnk:near, locate:near, prtchr:near
  77.     extrn    beep:near, puthlp:near, Close_Screen:near
  78.     extrn    serini:near, sendbr:near, showkey:near
  79.     EXTRN    PutMod:NEAR, Simulate_port_char:NEAR
  80.  
  81.     ASSUME cs:Code, ds:DataS
  82.  
  83. Quit_emulator DB ?        ; Flag to quit back to command mode
  84.  
  85. ; the show key command.
  86.  
  87. shokey    proc    near
  88.     mov    ah,cmcfm    ; confirm with carriage return
  89.     call    comnd
  90.      jmp    r        ; uh oh...
  91.     mov    dx,offset shkmsg
  92.     mov    ah,prstr
  93.     int    dos        ; print a prompt for it
  94.     mov    ax,offset targ    ; give it terminal arg block.
  95.     call    showkey        ; show them the key definition
  96.     push    ax
  97.     push    cx        ; save results
  98.     mov    dx,offset crlf
  99.     mov    ah,prstr
  100.     int    dos
  101.     pop    cx
  102.     pop    ax
  103.     call    prkey        ; print the buffer
  104.     mov    dx,offset crlf
  105.     mov    ah,prstr
  106.     int    dos
  107.     jmp    rskp        ; and return
  108. shokey    endp
  109.  
  110. ; pass a string pointer in ax, length in cx.
  111. ; Prints the string, quoting any unprintables, except crlf.
  112.  
  113. prkey    proc    near
  114.     mov    si,ax        ; copy string ptr
  115.     jcxz    prke6        ; no string, stop here
  116.     cld            ; Forwards
  117. prke1:    push    cx        ; save counter
  118.     lodsb            ; get a byte
  119.     and    al,7fH        ; only consider low-order 7 bits.
  120.     cmp    al,' '        ; printable?
  121.     jb    prke2        ; no, print the hard way
  122.     cmp    al,7fH        ; maybe a delete?
  123.     jne    prke4        ; no, can just put into string
  124. prke2:    jcxz    prke3        ; last char, can't be crlf
  125.     cmp    al,cr        ; carriage return?
  126.     jne    prke3        ; no, go on
  127.     cmp    byte ptr [si],lf ; followed by linefeed?
  128.     jne    prke3
  129.     mov    ah,prstr
  130.     mov    dx,offset crlf
  131.     int    dos        ; else just print crlf
  132.     inc    si        ; skip over lf
  133.     pop    cx        ; careful...
  134.     dec    cx
  135.     push    cx
  136.     jmp    short prke5
  137. prke3:    push    ax        ; preserve the char
  138.     mov    ah,conout
  139.     mov    dl,'\'
  140.     int    dos        ; print the quote character
  141.     pop    ax
  142.     call    proct        ; print the octal byte
  143.     jmp    short prke5
  144. prke4:    mov    dl,al        ; normal char, just print it
  145.     mov    ah,conout
  146.     int    dos
  147. prke5:    pop    cx        ; restore count
  148.     loop    prke1
  149. prke6:    ret            ; and return
  150. prkey    endp
  151.  
  152. ; print the byte in al as an octal number
  153. proct    proc    near
  154.     mov    dl,al            ; get the byte
  155.     and    dl,7h            ; keep low-order byte
  156.     mov    cl,3
  157.     shr    al,cl            ; shift to get next digit
  158.     jz    proc1            ; 0, no more to print
  159.     push    dx            ; else save current digit
  160.     call    proct            ; print rest
  161.     pop    dx
  162. proc1:    mov    ah,conout
  163.     add    dl,'0'            ; make printable
  164.     int    dos
  165.     ret
  166. proct    endp
  167.  
  168. ;    This is the CONNECT command.
  169.  
  170. TELNET     PROC    NEAR
  171.     mov ah,cmcfm
  172.     call comnd        ; Get a confirm.
  173.      jmp r            ;  Didn't get a confirm.
  174.  
  175.  
  176. ; Pre-confirmed entry to connect command ...
  177.  
  178. Telnet2:
  179.     mov cs:Quit_emulator, 0    ; We haven't quit yet
  180.     mov Preload_flag, 0    ; There is no preloaded command yet
  181.  
  182.     mov al,targ.flgs    ; get present flags
  183.     and al,modoff        ; this is only one we can keep around
  184.     or al,havtt        ; defaults (!)
  185.     cmp flags.debug,0    ; debug mode?
  186.     jz tel0            ; no, keep going
  187.     or al,trnctl        ; yes, show control chars
  188. tel0:    cmp flags.vtflg,0    ; vt52 emulation?
  189.     jz tel1
  190.     or al,emheath
  191. tel1:    mov bx,portval
  192.     cmp [bx].ecoflg,0    ; echoing?
  193.     jz tel2
  194.     or al,lclecho
  195. tel2:    mov targ.flgs,al    ; store flags
  196.     mov ah,flags.comflg
  197.     mov targ.prt,ah        ; Port 1 or 2
  198.     mov ah,trans.escchr
  199.     mov targ.escc,ah
  200.     mov ah,[bx].parflg
  201.     mov targ.parity,ah
  202.     mov ax,[bx].baud
  203.     mov targ.baudb,al
  204.     mov ah,flags.capflg
  205.     and ah,capt
  206.     or targ.flgs,ah
  207.     call serini        ; init serial port
  208.  
  209. tem:    mov ax,offset targ    ; Point to terminal arguments
  210.     call term
  211.     or targ.flgs,scrsam    ; assume screen is the same.
  212.  
  213. intchr:    test cs:Quit_emulator, 1 ; Flag to quit completely?
  214.      jnz intch0        ;  Yes, don't need another char
  215.  
  216.     mov ah, ConInQ        ; Quietly read a character
  217.     int Dos
  218.  
  219.     mov ah,al
  220.  
  221.     cmp ah,' '        ; Is it a space?
  222.      je tem            ;  Yes, go back to terminal emulation
  223.  
  224.     mov bh,ah        ; Save the actual char.
  225.     and ah,not ('a'-'A')    ; Convert to upper case.
  226.  
  227.     cmp ah,'C'        ; Is it close?
  228.     jne intch1
  229.  
  230.     call Close_Screen    ; Tell emulator to shut down
  231.  
  232. intch0:    call Check_for_preloaded_command ; Did host tell us to do something?
  233.     jmp rskp        ; and return
  234.  
  235. intch1: cmp ah,'S'        ; Is it status?
  236.     jnz intch2
  237.  
  238.     call stat0        ; If so, call stat0.
  239.     call puthlp        ; put help on screen
  240.     mov dx,offset sttmsg
  241.     call PutMod        ; Display a message in the mode line
  242.  
  243.     mov ah, ConInQ        ; Quietly read a character
  244.     int Dos
  245.  
  246.     and targ.flgs,not scrsam ; remember screen changed.
  247.     jmp tem
  248.  
  249. intch2: cmp ah,'B'        ; Send a break? [20g]
  250.     jne intch3        ; No. [20g]
  251.     call sendbr        ; Yes, so send a break. [20g]
  252.     jmp tem            ; And return.  [20g]
  253. intch3:    cmp ah,'M'        ; mode line?
  254.     jne intch4
  255.     xor targ.flgs,modoff    ; toggle mode line
  256.     jmp tem            ; and reconnect
  257.  
  258.  %OUT >> About half through source file
  259.  
  260. intch4:    cmp bh,'?'        ; Is it help?
  261.     jne intch5        ; If not, go to the next check.
  262.     mov ax,offset inthlp    ; If so, get the address of the help message.
  263.     call puthlp        ; write help msg
  264.     mov dx,offset intprm
  265.     call PutMod        ; Display a message in the mode line
  266.     and targ.flgs,not scrsam ; remember screen changed
  267.     jmp intchr        ; Get another char.
  268.  
  269. intch5: cmp bh,trans.escchr    ; Is it the escape char?
  270.     jne intch7        ;  No, try something else
  271.  
  272. intch6: mov ah,al        ; Escape char typed twice, send it out
  273.     call outchr
  274.      nop
  275.      nop
  276.      nop
  277.     jmp tem            ; Return, we are done here.
  278.  
  279. intch7:    cmp ah,'Q'        ; maybe want to stop logging?
  280.      jne intch8
  281.  
  282.     test targ.flgs,capt    ; not capturing, can't do this
  283.     jz intc10
  284.     and targ.flgs,not capt ; stop capturing
  285.     jmp tem            ; and resume
  286.  
  287. intch8:    cmp ah,'R'        ; maybe resume?
  288.      jne intch9        ; no, keep going
  289.  
  290.     cmp flags.capflg,0    ; can we capture?
  291.      jz intc10        ; no, forget it
  292.  
  293.     test targ.flgs,capt    ; already capturing?
  294.      jnz intc10        ; yes, can't toggle back on then
  295.  
  296.     or targ.flgs,capt    ; else turn flag on
  297.     jmp tem            ; and resume
  298.  
  299. intch9:    cmp bh,'0'        ; perhaps want a null (note original chr in bh)
  300.      jne intc10
  301.  
  302.     mov ah,0
  303.     call outchr
  304.      nop
  305.      nop
  306.      nop
  307.     jmp tem
  308.  
  309. intc10:    jmp tem            ; Wrong key, just give up
  310.  
  311. TELNET  ENDP
  312.  
  313.  
  314. ; Check for preloaded command ... if there is one, set it up as a macro,
  315. ;  turning single commas into Cr's, and pushing the result onto the TAKE stack
  316.  
  317. Check_for_preloaded_command PROC
  318.  
  319.     cmp Preload_flag, 0    ; Is there a preloaded command to be done?
  320.      je CPC_ret        ;  No
  321.  
  322.     cld            ; Forwards
  323.     inc TakLev        ; Bump take level
  324.     add takadr, SIZE takinfo ; Address new take frame
  325.     mov bx, TakAdr        ; Get TAKE frame addr into bx
  326.     mov BYTE PTR [bx].TakFcb, 0FFh ; Mark as a macro
  327.     mov si, OFFSET Preload_buffer ; Pointer to where preloaded command is
  328.     lea di, [bx].TakBuf    ; Put it in the TAKE buffer
  329.     sub cx, cx        ; Clear counter
  330.  
  331. CPC_1:    lodsb            ; Get a byte
  332.     cmp al, ','        ; Comma?
  333.      jne CPC_3        ;  No
  334.  
  335.     mov ah, BYTE PTR [si]    ; Peek at the next char
  336.     cmp ah, ','        ; Is it also a comma?
  337.      je CPC_2
  338.  
  339.     mov al, Cr        ; Convert single comma to a Cr
  340.     jmp SHORT CPC_3        ; Store it
  341.  
  342. CPC_2:    inc si            ; Skip over the "peeked" second comma
  343.  
  344. CPC_3:    stosb            ; Deposit char
  345.     inc cx            ; Count this char
  346.     or al, al        ; Hit end?
  347.      jne CPC_1        ;  Yes
  348.     
  349.     dec cx            ; Uncount the null at the end
  350.     lea ax, [bx].takbuf    ; Pick up ptr to start of TAKE buffer
  351.     mov [bx].takptr, ax    ; Init buffer ptr
  352.     mov [bx].takchl, cl    ; Chars remaining
  353.     mov [bx].takcnt, cx    ;  and all chars
  354.     mov [bx].takcnt+2, 0    ; Clear high order half
  355.  
  356. CPC_ret:
  357.     ret            ; Done here
  358.  
  359. Check_for_preloaded_command ENDP
  360.  
  361. ; Set parity for character in Register AL.
  362.  
  363. dopar:    push bx
  364.     mov bx,portval
  365.     cmp [bx].parflg,parnon    ; No parity?            [10 start]
  366.     je parret        ; Just return
  367.     cmp [bx].parflg,parevn    ; Even parity?
  368.     jne dopar0
  369.     and al,07FH        ; Strip parity.
  370.     jpe parret        ; Already even, leave it.
  371.     or al,080H        ; Make it even parity.
  372.     jmp parret
  373.  
  374. dopar0:    cmp [bx].parflg,parmrk    ; Mark parity?
  375.     jne dopar1
  376.     or al,080H        ; Turn on the parity bit.
  377.     jmp parret
  378.  
  379. dopar1:    cmp [bx].parflg,parodd    ; Odd parity?    
  380.     jne dopar2
  381.     and al,07FH        ; Strip parity.
  382.     jpo parret        ; Already odd, leave it.
  383.     or al,080H        ; Make it odd parity.
  384.     jmp parret
  385.  
  386. dopar2: and al,07FH        ; Space parity - turn off parity bit.
  387.  
  388. parret:    pop bx
  389.     ret                    ; [10 end]
  390.  
  391. inicpt    proc    near
  392.     mov    capbp,offset capbuf
  393.     mov    caplft,128        ; init buffer ptr & chrs left
  394.     ret                ; and return
  395. inicpt    endp
  396.  
  397.  
  398. ;   Capture routine, char in al
  399.  
  400. CptChr    PROC
  401.     push    di
  402.     mov    di,capbp
  403.     mov    byte ptr [di],al
  404.     inc    di
  405.     mov    capbp,di        ; restore pointer
  406.     pop    di
  407.     dec    caplft            ; decrement chars remaining
  408.      jnz    cptch1            ; more room, forget this part
  409.  
  410.     call    cptdmp            ; dump the info
  411.     call    inicpt            ; re-init ptrs.
  412.  
  413. cptch1:    ret                ; and return
  414.  
  415. cptchr    ENDP
  416.  
  417. cptdmp    proc    near            ; empty the capture buffer
  418.     push    ax
  419.     push    dx
  420.     mov    ah,setdma
  421.     mov    dx,offset capbuf    ; the capture routine buffer
  422.     int    dos
  423.     mov    ah,writef
  424.     mov    dx,offset cptfcb
  425.     int    dos            ; write out the block
  426.  
  427. ;*** must be fixed... check error returns, disable capturing,
  428. ;*** figure out how to put dma address back
  429.  
  430.     mov    dx,offset DTA
  431.     mov    ah,setdma
  432.     int    dos            ; put dma back
  433.  
  434.     pop    dx
  435.     pop    ax
  436.     ret
  437.  
  438. cptdmp    ENDP
  439.  
  440. clscpt    PROC
  441.  
  442.     mov    ah,cmcfm
  443.     call    comnd
  444.      jmp    r
  445.  
  446.     test    flags.capflg,0FFH    ; doing capture
  447.      jnz    clscpi            ; yes, go ahead
  448.  
  449.     mov    dx,offset erms22
  450.     mov    ah,prstr
  451.     int    dos
  452.  
  453.     jmp    rskp
  454.  
  455. clscpi:    mov    al,'Z'-64        ; control-z for eof...
  456.     call    cptchr            ; output to file
  457.     mov    al,caplft
  458.     cmp    al,128            ; is buffer empty?
  459.     je    clscp2            ; yes, forget this stuff
  460.     call    cptdmp            ; dump buffer (preserves registers)
  461. clscp2:    mov    ah,0
  462.     sub    word ptr cptfcb+16,ax    ; subtract remaining from low filsize
  463.     sbb    word ptr cptfcb+18,0    ; and from high size (with borrow)
  464.     mov    ah,closf
  465.     mov    dx,offset cptfcb
  466.     int    dos            ; close up file
  467.     mov    flags.capflg,0        ; no longer capturing...
  468.     jmp    rskp            ; and return
  469.  
  470. clscpt    ENDP
  471.  
  472. ; enter with ax/scan code to define, si/ pointer to definition, cx/ length
  473. ; of definition.  Defines it in definition table.
  474. ;*** somewhere should check for overflow etc of defbuf, and of scntab
  475. defkey    proc    near
  476.     push    ax        ; save scan code
  477.     cld            ; Forwards
  478.     mov    ax,ds
  479.     mov    es,ax        ; address data segment
  480.     mov    di,defptr    ; this is where the def gets built
  481.     inc    di        ; leave a byte for length
  482. defk1:    lodsb            ; get a byte from the source
  483.     cmp    al,'\'        ; escape?
  484.     jne    defk2        ; no, just deposit him
  485.     dec    cx        ; count available is one less
  486.     call    trnesc        ; translate the escape sequence
  487.     inc    cx        ; account for '\' (loop will decrement again).
  488. defk2:    stosb            ; drop off character
  489.     loop    defk1        ; and keep going while we have more
  490.     mov    ax,di        ; get ptr to end
  491.     dec    ax        ; back up pointer to end
  492.     mov    si,defptr    ; pick up old ptr value
  493.     sub    ax,si        ; this is actual length used
  494.     mov    byte ptr [si],al ; fill in length of entry
  495.     mov    defptr,di    ; this is next free byte
  496. ; definition address is in si
  497.     pop    ax        ; recover scan code
  498.     mov    cx,targ.klen    ; length of scan table
  499.     jcxz    defk4        ; not there, just go add it
  500.     mov    di,offset scntab ; the scan code table
  501.     repne    scasw        ; look for this one
  502.     jne    defk4        ; not defined already
  503.     sub    di,offset scntab + 2 ; compute index into table
  504.     mov    deftab[di],si    ; fill in address
  505.     ret            ; and return
  506.  
  507. defk4:    mov    di,targ.klen    ; get length again
  508.     inc    di
  509.     cmp    di,scntlen
  510.     ja    defk5        ;** ignore def if over size
  511.  
  512.     mov    targ.klen,di    ; update length
  513.     shl    di,1        ; double for word index
  514.     mov    scntab[di-2],ax    ; put scan code into table
  515.     mov    deftab[di-2],si    ; and fill in definition
  516.  
  517. defk5:    ret            ; that's it
  518.  
  519. defkey    ENDP
  520.  
  521.  
  522. ; enter with si/ source pointer, cx/ count
  523. ; converts an escape sequence, updates all pointers
  524.  
  525. trnesc    proc
  526.     push    bx
  527.     push    dx        ; preserve these
  528.     mov    al,0        ; this is current accumulation
  529.     jcxz    trnes2        ; empty string, forget it
  530.     mov    bl,3        ; this is max # of digits to use
  531.     mov    bh,8        ; this is radix
  532.  
  533. trnes1:    mov    dl,[si]
  534.     cmp    dl,'0'
  535.     jb    trnes2        ; out of range, stop here
  536.  
  537.     cmp    dl,'7'
  538.     ja    trnes2
  539.  
  540.     inc    si        ; accept character
  541.     sub    dl,'0'        ; convert to binary
  542.     mul    bh        ; shift accumulation
  543.     add    al,dl        ; add to accumulation
  544.     dec    bl        ; decrement digit counter
  545.     loopnz    trnes1        ; and keep trying
  546.  
  547. trnes2:    pop    dx
  548.     pop    bx
  549.     ret            ; and return
  550.  
  551. trnesc    endp
  552.  
  553. ; Jumping to this location is like retskp.  It assumes the instruction
  554. ;   after the call is a jmp addr.
  555.  
  556. RSKP    PROC    NEAR
  557.     pop bp
  558.     add bp,3
  559.     push bp
  560. ;    ret
  561. RSKP    ENDP
  562.  
  563. ; Jumping here is the same as a ret.
  564.  
  565. R    PROC    NEAR
  566.     ret
  567. R    ENDP
  568.  
  569. Code    ENDS
  570.  
  571.     END
  572. 
  573.